package com.water_work_form.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.water_work_form.entity.RecordCoagulation;
import com.water_work_form.entity.RecordMudContent;
import com.water_work_form.mapper.BasicFormMapper;
import com.water_work_form.result.Result;
import com.water_work_form.result.ResultCodeEnum;
import com.water_work_form.result.ResultUtil;
import com.water_work_form.service.RecordCoagulationService;
import com.water_work_form.util.RandomIdUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.*;

/**
 * <p>
 * 记录——混凝实验原始记录 前端控制器
 * </p>
 *
 * @author xuke
 * @since 2023-08-25
 */
@RestController
@RequestMapping("/record-coagulation")
public class RecordCoagulationController {

    @Autowired
    RecordCoagulationService recordCoagulationService;

    @Autowired
    BasicFormMapper basicFormMapper;

    /**
     * 记录——混凝实验原始记录 项目新增
     * @param recordCoagulation 新项目
     * @return 返回相应result，code 0为成功
     */
    @ApiOperation("新增")
    @PostMapping("/add")
    public Result addRecordCoagulation(@RequestBody RecordCoagulation recordCoagulation){
        recordCoagulation.setId(RandomIdUtil.createRandomId());
        recordCoagulationService.save(recordCoagulation);
        return ResultUtil.success(ResultCodeEnum.SUCCESS, recordCoagulation);
    }

    /**
     * 记录——混凝实验原始记录 项目查询
     * @param checkSite 检测地点（check_site）
     * @param current 分页 当前页
     * @param startSampleDate 取样日期（sample_date）范围查询开始日期
     * @param endSampleDate 取样日期（sample_date）范围查询结束日期
     * @param size 分页 每页数据量
     * @param status 状态
     * @return 返回对应数据
     */
    @ApiOperation("查看(分页)")
    @GetMapping("/pageList")
    public Result listRecordCoagulation(@RequestParam("checkSite") String checkSite, @RequestParam("current") Integer current, @RequestParam("startSampleDate") String startSampleDate,
                                        @RequestParam("endSampleDate") String endSampleDate, @RequestParam("size") Integer size, @RequestParam("status") String status){
        IPage<RecordCoagulation> page = recordCoagulationService.selectRecordCoagulation(checkSite, status, startSampleDate, endSampleDate, current, size);
        return ResultUtil.success(ResultCodeEnum.SUCCESS, page);
    }

    /**
     * 记录——混凝实验原始记录 项目删除
     * @param id 需删除的项目id
     * @return 返回result，code 0成功
     */
    @ApiOperation("删除")
    @DeleteMapping("/delete")
    public Result deleteRecordCoagulation(@RequestParam("id") Long id){
        recordCoagulationService.removeById(id);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }

    /**
     * 记录——混凝实验原始记录 项目更新
     * @param recordCoagulation 更新的项目
     * @return 返回result，code 0成功
     */
    @ApiOperation("更新")
    @PostMapping("/update")
    public Result updateRecordCoagulation(@RequestBody RecordCoagulation recordCoagulation){
        recordCoagulationService.updateById(recordCoagulation);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }

    /**
     * 记录——混凝实验原始记录 基础表数据查询
     * @param name form表name
     * @return 返回对应数据
     */
    @ApiOperation("基础表数据查询")
    @GetMapping("/basicList")
    public Result listCoagulation(@RequestParam("name") String name){
        Map<String,Object> map = recordCoagulationService.selectBasicCoagulation(name);
        return ResultUtil.success(ResultCodeEnum.SUCCESS, map);
    }

    /**
     * 记录——混凝实验原始记录 数据表导出
     * @param recordCoagulation 需要导出的数据列表
     * @return 返回相应数据
     * @throws IOException 异常
     */
    @ApiOperation("列表导出")
    @PostMapping(value = "/download-word")
    public Result downloadWordRecordCoagulation(@RequestBody RecordCoagulation recordCoagulation) throws IOException  {
        recordCoagulationService.downloadRecordCoagulation(recordCoagulation);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }


}

